<?php

namespace app\web\controller;

use app\web\service\BusesService;

// 固定路线控制器
class BusesController extends CommonController
{
    public function initialize()
    {
        $this->noCheckTokenAction = ["getHomeData", "getHotLineList", "getSearchData"];
//        $this->noCheckTokenAction = array_merge($this->noCheckTokenAction, ["getOrderData", "toSubmitOrder"]);
        parent::initialize();
    }

    // 固定路线页面的基本数据
    public function getHomeData(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(BusesService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getIndexData();
        return $this->return_result($this->returnData);
    }

    // 搜索的数据
    public function getSearchData(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(BusesService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getSearchData();
        return $this->return_result($this->returnData);
    }

    // 下订单页的数据
    public function getOrderData(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(BusesService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getOrderData($this->app->request->userLoginData["id"]);
        return $this->return_result($this->returnData);
    }

    // 提交订单
    public function toSubmitOrder(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(BusesService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toSubmitOrder($this->app->request->userLoginData["id"], $this->app->request->userLoginData["openid"]);
        return $this->return_result($this->returnData);
    }

    // 获取热门线路列表，分页
    public function getHotLineList(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(BusesService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getHotLineByPaint();
        return $this->return_result($this->returnData);
    }
}
